package com.zxe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxe.utils.ConvertUtils;
import com.zxe.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zxe.dao.OrderDao;
import com.zxe.dto.OrderDTO;
import com.zxe.dto.UserDTO;
import com.zxe.entity.OrderEntity;
import com.zxe.entity.UserEntity;
import com.zxe.feign.UserFeignService;
import com.zxe.service.OrderService;

import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl extends CrudServiceImpl<OrderDao, OrderEntity, OrderDTO> implements OrderService {

    @Autowired
    private UserFeignService userFeignService;

    @Override
    public QueryWrapper<OrderEntity> getWrapper(Map<String, Object> params) {
        return null;
    }

    @Override
    public OrderDTO getById(Integer id){
        OrderDTO dto = ConvertUtils.sourceToTarget(baseDao.selectById(id), OrderDTO.class);
        Result<UserEntity> r = userFeignService.getUserById(id);
        dto.setUserEntity(r.getData());
        return dto;
    }

    @Override
    public List<UserDTO> getAll() {
        Result<List<UserDTO>> r = userFeignService.getAll();
        return r.getData();
    }
}
